#include "tmp.h"

void cryptTable(unsigned long* crypt_table){
	unsigned long seed = 0x00100001;
	unsigned long index1 = 0;
	unsigned long index2 = 0;
	unsigned long i;

	for (index1 = 0; index1 < 0x100; ++index1)
		for (index2 = index1, i = 0; i < 5; ++i,index2 += 0x100){
			unsigned long temp1,temp2;
			seed = (seed*125 + 3)%0x2AAAAB;
			temp1 = (seed & 0xFFFF)<<0x10;
			seed = (seed*125 + 3)%0x2AAAAB;
			temp2 = (seed & 0xFFFF);
			crypt_table[index2] = (temp1 | temp2);
		}
}

unsigned long hashString(const string& target,unsigned long* crypt_table,unsigned long hash_type){
	string::const_iterator key = target.begin();
	unsigned long seed1 = 0x7FED7FED;
	unsigned long seed2 = 0xEEEEEEEE;
	int ch;
	while (key != target.end()){
		ch = toupper(*key++);
		cout<<static_cast<unsigned char>(ch)<<"__";
		seed1 = crypt_table[(hash_type << 8) + ch]^(seed1 + seed2);
		seed2 = ch + seed1 + seed2 + (seed2 << 5) + 3;
	}
	return seed1;
}
